package com.zb.Service.impl;

import com.zb.Service.UserService;
import com.zb.mapper.UserMapper;
import com.zb.pojo.User;
import com.zb.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class UserServiceImpl implements UserService {

    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    public void registerUser(User user) {
        //获取session对象
        SqlSession sqlSession = factory.openSession();
        //获取mapper对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //调用方法
        mapper.registerUser(user);
        sqlSession.commit();
        //释放资源
        sqlSession.close();
    }

    public User loginUser(String userName, String passWord) {
        //获取session对象
        SqlSession sqlSession = factory.openSession();
        //获取mapper对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

//        User u=new User();
//        u.setUserName(userName);
//        u.setPassWord(passWord);
        //User user = mapper.loginUser222(u);

        //调用方法
        User user = mapper.loginUser(userName, passWord);
        //释放资源
        sqlSession.close();

        return user;
    }
}
